package com.gxa.admin.recycling.controller;

import com.gxa.admin.recycling.service.ScoreService;
import com.gxa.core.recycling.common.JsonResult;
import com.gxa.core.recycling.util.StringUtil;
import com.gxa.core.recycling.util.TimeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.util.Map;

/**
 * @author R
 * @data 2021-12-07 14:06
 */
@RequestMapping("/score")
@RestController
@Api(tags = "签到统计")
public class ScoreController {

    @Autowired
    ScoreService service;

    @PostMapping("/getAll")
    @ApiOperation("获得签到统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "小区名称",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "cycle",value = "统计周期",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "from",value = "自定义事件起止日期",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "to",value = "自定义事件截止日期",required = false,dataType = "String",paramType = "query")
    })
    public Map getAll(String name,String cycle,String from,String to){
        String end = null;
        String start = null;
        System.out.println("cycle:"+cycle);
        if (!StringUtil.isEmpty(cycle)){
            end = new Timestamp(System.currentTimeMillis()).toString();
            start = TimeUtil.rollBackTime(cycle);
        }
        System.out.println("end:"+end);
        System.out.println("start:"+start);
        System.out.println("from:"+from);
        System.out.println("to:"+to);
        Map<String, Object> sign = service.getSign(start, end, from, to, name);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.setData(sign);
        return jsonResult.getDataMap();
    }
}
